<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Button Test Suite</title>
<link type="text/css" rel="stylesheet" href="../../../js/tinymce/skins/lightgray/skin.min.css" />
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<link rel="stylesheet" href="css/ui-overrides.css" type="text/css" />
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css" type="text/css" />
<script src="http://code.jquery.com/qunit/qunit-git.js"></script>
<script src="../../js/qunit/reporter.js"></script>
<script src="../../js/utils.js"></script>
<script src="../../js/tinymce_loader.js"></script>
<script type="text/javascript">
QUnit.config.autostart = false;
QUnit.config.reorder = false;

module("ui.ColorButton", {
	setup: function() {
		document.getElementById('view').innerHTML = '';
	},

	teardown: function() {
		//document.getElementById('view').innerHTML = '';
	}
});

window.onload = function() {
	QUnit.start();
};

function createColorButton(settings) {
	return tinymce.ui.Factory.create(tinymce.extend({
		type: 'colorbutton'
	}, settings)).renderTo(document.getElementById('view'));
}

test("colorbutton text, size default", function() {
	var colorButton = createColorButton({text: 'X'});

	nearlyEqualRects(rect(colorButton), [0, 0, 42, 30], 4);
});

test("colorbutton text, size large", function() {
	var colorButton = createColorButton({text: 'X', size: 'large'});

	nearlyEqualRects(rect(colorButton), [0, 0, 49, 39], 4);
});

test("colorbutton text, size small", function() {
	var colorButton = createColorButton({text: 'X', size: 'small'});

	nearlyEqualRects(rect(colorButton), [0, 0, 34, 23], 4);
});

test("colorbutton text, width 100, height 100", function() {
	var colorButton = createColorButton({text: 'X', width: 100, height: 100});

	deepEqual(rect(colorButton), [0, 0, 100, 100]);
	deepEqual(rect(colorButton.getEl().firstChild), [1, 1, 98, 98]);
});

test("colorbutton icon, size default", function() {
	var colorButton = createColorButton({icon: 'test'});

	nearlyEqualRects(rect(colorButton), [0, 0, 50, 30], 4);
});

test("colorbutton icon, size small", function() {
	var colorButton = createColorButton({icon: 'test', size: 'small'});

	nearlyEqualRects(rect(colorButton), [0, 0, 43, 24], 4);
});

test("colorbutton icon, size large", function() {
	var colorButton = createColorButton({icon: 'test', size: 'large'});

	nearlyEqualRects(rect(colorButton), [0, 0, 54, 40], 4);
});

test("colorbutton icon, width 100, height 100", function() {
	var colorButton = createColorButton({icon: 'test', width: 100, height: 100});

	deepEqual(rect(colorButton), [0, 0, 100, 100]);
	deepEqual(rect(colorButton.getEl().firstChild), [1, 1, 98, 98]);
});

test("colorbutton text & icon, size default", function() {
	var colorButton = createColorButton({text: 'X', icon: 'test'});

	nearlyEqualRects(rect(colorButton), [0, 0, 62, 30], 4);
});

test("colorbutton text & icon, size large", function() {
	var colorButton = createColorButton({text: 'X', icon: 'test', size: 'large'});

	nearlyEqualRects(rect(colorButton), [0, 0, 69, 40], 4);
});

test("colorbutton text & icon, size small", function() {
	var colorButton = createColorButton({text: 'X', icon: 'test', size: 'small'});

	nearlyEqualRects(rect(colorButton), [0, 0, 53, 24], 4);
});

test("colorbutton text & icon, width 100, height 100", function() {
	var colorButton = createColorButton({text: 'X', icon: 'test', width: 100, height: 100});

	deepEqual(rect(colorButton), [0, 0, 100, 100]);
	deepEqual(rect(colorButton.getEl().firstChild), [1, 1, 98, 98]);
});

test("colorbutton click event", function() {
	var colorButton, clicks = {};

	colorButton = createColorButton({text: 'X', onclick: function() {clicks.a = 'a';}});
	colorButton.renderTo(document.getElementById('view'));
	colorButton.fire('click', {target: colorButton.getEl()});

	deepEqual(clicks, {a: 'a'});
});
</script>
</head>
<body>
	<h1 id="qunit-header">Button Test Suite</h1>
	<h2 id="qunit-banner"></h2>
	<h2 id="qunit-userAgent"></h2>
	<ol id="qunit-tests">
	</ol>
	<div id="view" style="position: absolute; right: 0; top: 0"></div>
</body>
</html>
